home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Utilities / Programming / EnterAct 3.5 / Drag_on Modules / hAWK programs / $CopyFiles < prev    next >
Encoding:
Text File  |  1992-12-13  |  1.1 KB  |  42 lines  |  [TEXT/KEEN]

  1. # $CopyFiles : Copy file(s) to same folder, appending 'x' to each name.
  2. # Use with single specific file, or a selection of files.
  3. # Revised to use the copy() command - quick, and the resource
  4. # fork is preserved. Copies any kind of file.
  5. # Input from "Select input file..." or "MFS selected files" - it's
  6. # only the file names and locations that matter.
  7. # stdout contains a brief summary afterwards.
  8.  
  9. BEGIN {
  10.     CopyTheFiles();
  11.     print ARGC-1, "files were copied, no problems."
  12.     }
  13.  
  14. function CopyTheFiles(    i, outfile)
  15.     {
  16.     for (i = 1; i < ARGC; ++i)#note ARGV[0] is just "hAWK"
  17.         {
  18.         outfile = MakeNewFileName(i)
  19.         if (!copy(ARGV[i], outfile))
  20.             {
  21.             print "Error, could not copy", ARGV[i]
  22.             exit
  23.             }
  24.         print ARGV[i]
  25.         print "\t\twas copied to"
  26.         print outfile
  27.         print ""
  28.         }
  29.     }
  30.  
  31. function MakeNewFileName(which,    z, j, outfile)
  32.     {
  33.     z = split(ARGV[which], names, ":");
  34.     names[z] = names[z] "x"
  35.     if (length(names[z]) > 31)
  36.         names[z] = substr(names[z], 1, 30) "x" #trim last letter - not elegant...
  37.     outfile = names[z]
  38.     for (j = z-1; j >= 1; --j) #put full path name back together
  39.         outfile = names[j] ":" outfile;
  40.     return outfile
  41.     }
  42.